package Bi_Tree.level_traversal;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class lc429 {
    public List<List<Integer>> levelOrder(Node root) {
        List<List<Integer>> result=new ArrayList<>();
        Queue<Node>  queue=new LinkedList<>();
        if(root==null){
            return result;
        }
        Node node=root;
        queue.offer(node);
        while (!queue.isEmpty()){
            List<Integer> smalllist=new ArrayList<>();
            int len= queue.size();
            while (len>0){
                node=queue.poll();
                smalllist.add(node.val);
                for (Node node_:node.children
                     ) {
                    queue.offer(node_);
                }
                len--;
            }
            result.add(smalllist);
        }
        return result;

    }
}
class Node {
    public int val;
    public List<Node> children;

    public Node() {}

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, List<Node> _children) {
        val = _val;
        children = _children;
    }
}